
// ignore_for_file: non_constant_identifier_names

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:verse_systems/res/colors.dart';
import 'package:verse_systems/widgets/sp_button.dart';

typedef ResultBlock = void Function(Map result);

class ChoosePickerView extends StatefulWidget {
  final bool  confirm_amount;
  final List params;
  final ResultBlock onResult;

  const ChoosePickerView({super.key, required this.params, required  this.onResult ,this.confirm_amount = false});

  @override
  State<ChoosePickerView> createState() => _ChoosePickerViewState();
}

class _ChoosePickerViewState extends State<ChoosePickerView> {
  int selectedItem = 0;

  @override
  Widget build(BuildContext context) {
    return Material(
      child: SizedBox(
      height: 300.w,
      child:Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          Container(
            height: 60.w,
            decoration: BoxDecoration(
              border: Border(
                  bottom: BorderSide(
                      color: Colors.grey.withOpacity(0.1), width: 1)),
            ),
            child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.only(left: 25.w),
                    width: 95.w,
                    child: SPButton(
                      minHeight: 35.w,
                      fontSize: 13.sp,
                      text: 'cancel'.tr,
                      textColor: Colours.app_main_background_color,
                      radius: 17.5.w,
                      side: const BorderSide(
                        color: Colours.app_main_background_color,
                        width: 1.0,
                      ),
                      onPressed: () {
                        Navigator.of(context).pop();
                      },
                    ),
                  ),
                  Container(
                    margin: EdgeInsets.only(right: 25.w),
                    width: 95.w,
                    child: SPButton(
                      minHeight: 35.w,
                      fontSize: 13.sp,
                      text: "confirm".tr,
                      textColor: Colours.app_main_color,
                      backgroundColor: Colours.app_main_background_color,
                      radius: 17.5.w,
                      onPressed: () async {
                        Navigator.of(context).pop();
                        widget.onResult(widget.params[selectedItem]);
                      },
                    ),
                  ),
                ]),
          ),
          Expanded(
            child:CupertinoPicker(
            onSelectedItemChanged: (index) {
              selectedItem = index;
            },
            itemExtent: 36,
            children: widget.params.map((item) {
              return Center(
                child: Text(
                  widget.confirm_amount? item['amount']['key'].toString(): item['value'].toString(),
                  style: const TextStyle(color: Colors.black87, fontSize: 16),
                  maxLines: 1,
                ),
              );
            }).toList(),
          ))
        ],
      )),
    );
  }
}
